package com.insta.formation.library.service.impl;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.insta.formation.library.dao.impl.BookDaoImpl;
import com.insta.formation.library.dao.impl.ExemplaryDaoImpl;
import com.insta.formation.library.dao.impl.UserDaoImpl;
import com.insta.formation.library.model.IBook;
import com.insta.formation.library.model.IExemplary;
import com.insta.formation.library.model.IRentBook;
import com.insta.formation.library.model.IUser;
import com.insta.formation.library.service.IAdminService;

public class AdminServiceImpl implements IAdminService {

	final private static Logger LOGGER = LoggerFactory.getLogger(BookDaoImpl.class);
	
	public void ShowLibrary() 
	{
		 ServiceFactoryImpl srv = new ServiceFactoryImpl();
		 srv.ShowLibrary();
	}


	public boolean RentBook(IRentBook rentbook) {
		ServiceFactoryImpl srv = new ServiceFactoryImpl();
		return srv.RentBook(rentbook);

	}

	public void DeleteOwnCount(IUser user) {
		ServiceFactoryImpl srv = new ServiceFactoryImpl();
		srv.DeleteOwnCount(user);
	}

	public void DeleteUserAccount(IUser user) {
		UserDaoImpl user_dao = new UserDaoImpl();
		user_dao.delete(user);
	}
	public void CreateUserAccount(IUser user) {
		UserDaoImpl user_dao = new UserDaoImpl();
		user_dao.create(user);
	}

	public boolean AddLibrary(IBook book,int nbr_add) {
		ExemplaryDaoImpl exp = new ExemplaryDaoImpl();
		try
		{
			exp.AddExemplary(book, nbr_add);
			return true;
		}
		catch (Exception e)
		{
			LOGGER.error(e.getMessage());
		}
		return false;
	}

	public boolean removeLibrary(IBook book,int nbr_remove) {
		ExemplaryDaoImpl exp = new ExemplaryDaoImpl();
		try
		{
			exp.RemoveExemplary(book, nbr_remove);
			return true;
		}
		catch (Exception e)
		{
			LOGGER.error(e.getMessage());
		}
		return false;

	}

	public IExemplary FindLibrary(IBook book) {
		ExemplaryDaoImpl exp = new ExemplaryDaoImpl();
		return exp.find(book.getId());
	}




}
